namespace Drill.Core.Utilities.Extensions
{
	/// <summary>
	/// String extension methods that provide a convenient way of performing conversions.
	/// </summary>
    public static class StringExtensionMethods
    {
		/// <summary>
		/// Converts the string to a <see cref="bool"/> value.
		/// </summary>
		/// <param name="value">The string value.</param>
		/// <returns>
		/// A <see cref="bool"/> value parsed from the specified <paramref name="value"/> 
		/// or is the default value, <c>false</c>.
		/// </returns>
        public static bool ToBoolean(this string value)
        {
            return ToBoolean(value, false);
        }

		/// <summary>
		/// Converts the specified string value.
		/// </summary>
		/// <param name="value">The string representation of a boolean value.</param>
		/// <param name="defaultValue">
		/// The default value to be returned if the <paramref name="value"/> cannot be parsed.
		/// </param>
		/// <returns>
		/// An <see cref="bool"/> value that was either converted from the specified 
		/// <paramref name="value"/> of the specified <paramref name="defaultValue"/>.
		/// </returns>
        public static bool ToBoolean(this string value, bool defaultValue)
        {
            return StringToBooleanConverter.Convert(value, defaultValue);
        }

		/// <summary>
		/// Converts the string to an <see cref="int"/> value.
		/// </summary>
		/// <param name="value">The string value.</param>
		/// <returns>
		/// An <see cref="int"/> value parsed from the specified <paramref name="value"/> 
		/// or is the default value, <c>-1</c>.
		/// </returns>
        public static int ToInt32(this string value)
        {
            return ToInt32(value, -1);
        }

		/// <summary>
		/// Converts the specified string value.
		/// </summary>
		/// <param name="value">The string representation of a 32-bit integer value.</param>
		/// <param name="defaultValue">
		/// The default value to be returned if the <paramref name="value"/> cannot be parsed.
		/// </param>
		/// <returns>
		/// An <see cref="int"/> value that was either converted from the specified 
		/// <paramref name="value"/> of the specified <paramref name="defaultValue"/>.
		/// </returns>
        public static int ToInt32(this string value, int defaultValue)
        {
            return StringToInt32Converter.Convert(value, defaultValue);
        }
    }
}